﻿#pragma once
#ifndef CHATWIDGET_H
#define CHATWIDGET_H

#include <QWidget>
#include <QMouseEvent>
#include <QGraphicsDropShadowEffect>
#include <QMessageBox>
#include "MyPDU.h"
#include <QDebug>
#include <QFontMetrics>
#include <QLabel>
#include "chatdb.h"
#include "widget.h"


class ChatSocket;
namespace Ui {
class ChatWidget;
}

class ChatWidget : public QWidget
{
    Q_OBJECT
    enum BorderIndex{BORDER_NONE,BORDER_TOP,BORDER_BOTTOM,BORDER_LEFT,BORDER_RIGHT,
                    BORDER_LEFT_TOP,BORDER_RIGHT_TOP,BORDER_LEFT_BOTTOM,BORDER_RIGHT_BOTTOM};
public:
    explicit ChatWidget(QWidget *parent = nullptr);
    ~ChatWidget();
    void setWinName(QString nickname);//设置聊天人信息
    QString getWinName();
    QWidget* CreateWidgetL_R(int i, QString name, QString data);//创建左右窗口
    void addMsgWidget(QWidget* widget);
    void restoreChatLog(QString msg);//恢复聊天记录
private:
    void setShadow();
    void loadImg();
    BorderIndex getRegion(QPoint pos);//获取鼠标在哪个区域
    void setMouseTrack();//开启鼠标捕获
    void SetCursorByRegoinIndex(BorderIndex region_index);//根据区域改变鼠标形状
protected:
    void mousePressEvent(QMouseEvent *event);//鼠标点击
    void mouseMoveEvent(QMouseEvent *event);//鼠标移动
    void mouseReleaseEvent(QMouseEvent *event);//鼠标释放
private slots:
    void on_tool_close_clicked();

    void on_btn_sendMsg_clicked();

signals:
    void textMsg(QString,QString);
private:
    Ui::ChatWidget *ui;
    bool isPressedWidget;//isPressedWidget控制窗口移动
    QPoint last_point,last_position;//记录窗口位置和全局位置
    BorderIndex m_mouse_region;//鼠标按下时所在区域
    ChatSocket* m_pChatSocket;
};

#endif // CHATWIDGET_H
